<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible">
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="100px"
      v-loading="formLoading"
    > 
    <el-tabs  v-model="activeName">
      <el-tab-pane label="基本信息" name="basic">
        <el-form-item label="资产分类" prop="categoryId">
          <!-- <el-select filterable v-model="formData.categoryId" class="!w-240px" placeholder="资产分类" clearable>
            <el-option
              v-for="(user, index) in CatalogList"
              :label="user.name"
              :value="user.id"
              :key="index"
            />
          </el-select> -->
          <el-tree-select
            v-model="formData.categoryId"
            :data="CatalogList"
            :props="defaultProps"
            check-strictly
            filterable
            class="!w-240px"
            node-key="id"
            placeholder="请选择资产分类"
          />
        </el-form-item>
        <el-form-item label="资产名称" prop="name">
          <el-input v-model="formData.name" placeholder="请输入资产名称" />
        </el-form-item>
        <el-form-item label="归属" prop="ownerCode">
          <el-select filterable v-model="formData.ownerCode" class="!w-240px" placeholder="归属" clearable>
            <el-option
              v-for="dict in getStrDictOptions(DICT_TYPE.eam_gs)"
              :key="dict.value"
              :label="dict.label"
              :value="(dict.value)"
            />
          </el-select>
         
        </el-form-item>
        <el-form-item label="归属公司" prop="ownCompanyId">
          <el-select filterable v-model="formData.ownCompanyId" class="!w-240px" placeholder="归属公司" clearable>
            <el-option
            v-for="dict in getStrDictOptions(DICT_TYPE.company_type)"
            :key="dict.value"
            :label="dict.label"
            :value="Number(dict.value)"
            />
          </el-select>
         
        </el-form-item>
        <el-form-item label="归属部门" prop="useOrganizationId">
          <el-tree-select
            v-model="formData.useOrganizationId"
            :data="deptList"
            :props="defaultProps"
            check-strictly
            filterable
            class="!w-240px"
            node-key="id"
            placeholder="请选择归属部门"
          />
        </el-form-item>
        <el-form-item label="资产状态" prop="assetStatus">
          <el-select filterable v-model="formData.assetStatus" class="!w-240px" placeholder="资产状态" clearable>
            <el-option
            v-for="dict in getStrDictOptions(DICT_TYPE.eam_zc_status)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            />
          </el-select>
         
        </el-form-item>
        <!-- <el-form-item label="资产来源" prop="sourceId">
          <el-input v-model="formData.sourceId" placeholder="请输入来源" />
            <el-select v-model="formData.sourceId" placeholder="请选择资产来源" clearable class="!w-240px">
              <el-option
                v-for="dict in getStrDictOptions(DICT_TYPE.eam_zc_source)"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
          </el-select>
        </el-form-item> -->
        <el-form-item label="资产编号" prop="assetCode">
          <el-input v-model="formData.assetCode" placeholder="请输入资产编号" />
        </el-form-item>
        <el-form-item label="管理人员" prop="managerId">
          <el-select filterable v-model="formData.managerId" class="!w-240px" placeholder="管理人员" clearable>
            <el-option
              v-for="(user, index) in userList"
              :label="user.nickname"
              :value="user.id"
              :key="index"
            >
            {{user.nickname}}({{user.username}})
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="资产厂商" prop="categoryId">
          <el-select filterable v-model="formData.categoryId" class="!w-240px" placeholder="资产厂商" clearable>
            <el-option
              v-for="(user, index) in CatalogList"
              :label="user.name"
              :value="user.id"
              :key="index"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item label="规格型号" prop="model">
          <el-input v-model="formData.model" placeholder="请输入规格型号" />
        </el-form-item>
        <!-- <el-form-item label="资产序列" prop="serialNumber">
          <el-input v-model="formData.serialNumber" placeholder="请输入资产序列" />
        </el-form-item> -->
        <!-- <el-form-item label="使用人员" prop="useUserId">
          <el-select filterable v-model="formData.useUserId" class="!w-240px" placeholder="使用人员" clearable>
            <el-option
              v-for="(user, index) in userList"
              :label="user.nickname"
              :value="user.id"
              :key="index"
            />
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="资产用途" prop="purpose">
          <el-input v-model="formData.purpose" placeholder="请输入资产用途" />
        </el-form-item>
        <el-form-item label="计量单位" prop="unit">
          <el-input v-model="formData.unit" placeholder="请输入计量单位" />
        </el-form-item> -->
        <el-form-item label="位置" prop="positionId">
          <el-select filterable v-model="formData.positionId" class="!w-240px" placeholder="请选择位置" clearable>
            <el-option
            v-for="dict in getStrDictOptions(DICT_TYPE.eam_position)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            />
          </el-select>
          <!-- <el-input v-model="formData.positionId" placeholder="请选择位置" /> -->
        </el-form-item>
        <el-form-item label="详细地址" prop="positionDetail">
          <el-input v-model="formData.positionDetail" placeholder="请输入详细地址" />
        </el-form-item>
        <!-- <el-form-item label="资产RFID" prop="rfid">
          <el-input v-model="formData.rfid" placeholder="请输入资产RFID" />
        </el-form-item>
        <el-form-item label="资产标签" prop="equipmentLabel">
          <el-input v-model="formData.equipmentLabel" placeholder="请输入资产标签" />
        </el-form-item> -->
        <el-form-item label="资产备注" prop="assetNotes">
          <el-input v-model="formData.assetNotes" placeholder="请输入资产备注" />
        </el-form-item>
        <el-form-item label="附件" prop="attach">
          <!-- <el-input v-model="formData.attach" placeholder="请输入附件" /> -->
          <UploadFile v-model="formData.attach" class="min-w-80px" />
        </el-form-item>
        <el-form-item label="图片" prop="pictureId">
          <!-- <el-input v-model="formData.pictureId" placeholder="请输入标准型号物品图片" /> -->
          <UploadImg
            v-model="formData.pictureId"
            draggable="false"
            height="80px"
            width="100%"
            class="min-w-80px"
          />
        </el-form-item>
        <!-- <el-form-item label="分类编码" prop="categoryCode">
          <el-input v-model="formData.categoryCode" placeholder="请输入分类编码" />
        </el-form-item>
        <el-form-item label="业务编号" prop="businessCode">
          <el-input v-model="formData.businessCode" placeholder="请输入业务编号" />
        </el-form-item>
        <el-form-item label="流程ID" prop="procId">
          <el-input v-model="formData.procId" placeholder="请输入流程ID" />
        </el-form-item> -->
        <!-- <el-form-item label="办理状态" prop="status">
          <el-radio-group v-model="formData.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <!-- <el-form-item label="批次编码" prop="batchCode">
          <el-input v-model="formData.batchCode" placeholder="请输入批次编码" />
        </el-form-item>
        <el-form-item label="归属" prop="ownerCode">
          <el-input v-model="formData.ownerCode" placeholder="请输入归属" />
        </el-form-item>-->
       
       
        <!-- <el-form-item label="是否显示" prop="display">
          <el-input v-model="formData.display" placeholder="请输入是否显示" />
        </el-form-item>
        <el-form-item label="清理类型" prop="cleanOutType">
          <el-select v-model="formData.cleanOutType" placeholder="请选择清理类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否清理" prop="cleanOut">
          <el-input v-model="formData.cleanOut" placeholder="请输入是否清理" />
        </el-form-item>
        <el-form-item label="清理时间" prop="cleanTime">
          <el-date-picker
            v-model="formData.cleanTime"
            type="date"
            value-format="x"
            placeholder="选择清理时间"
          />
        </el-form-item>
        <el-form-item label="标准物品档案" prop="goodsId">
          <el-input v-model="formData.goodsId" placeholder="请输入标准物品档案" />
        </el-form-item>
       
        <el-form-item label="标准型号厂商" prop="manufacturerId">
          <el-input v-model="formData.manufacturerId" placeholder="请输入标准型号厂商" />
        </el-form-item>
        
        
        
        <el-form-item label="使用期限,(月)" prop="serviceLife">
          <el-input v-model="formData.serviceLife" placeholder="请输入使用期限,(月)" />
        </el-form-item>
        <el-form-item label="安全等级" prop="safetyLevelCode">
          <el-input v-model="formData.safetyLevelCode" placeholder="请输入安全等级" />
        </el-form-item>
        
        
        
        <el-form-item label="仓库" prop="warehouseId">
          <el-input v-model="formData.warehouseId" placeholder="请输入仓库" />
        </el-form-item>
        <el-form-item label="库存物品" prop="goodsStockId">
          <el-input v-model="formData.goodsStockId" placeholder="请输入库存物品" />
        </el-form-item>
        
        <el-form-item label="资产数量" prop="assetNumber">
          <el-input v-model="formData.assetNumber" placeholder="请输入资产数量" />
        </el-form-item>
        <el-form-item label="剩余数量" prop="remainNumber">
          <el-input v-model="formData.remainNumber" placeholder="请输入剩余数量" />
        </el-form-item>
        <el-form-item label="采购日期" prop="purchaseDate">
          <el-date-picker
            v-model="formData.purchaseDate"
            type="date"
            value-format="x"
            placeholder="选择采购日期"
          />
        </el-form-item>
        <el-form-item label="生产日期" prop="productionDate">
          <el-date-picker
            v-model="formData.productionDate"
            type="date"
            value-format="x"
            placeholder="选择生产日期"
          />
        </el-form-item>
        <el-form-item label="入账日期" prop="registerDate">
          <el-date-picker
            v-model="formData.registerDate"
            type="date"
            value-format="x"
            placeholder="选择入账日期"
          />
        </el-form-item>
       
       
        <el-form-item label="最近核对日期" prop="lastVerificationDate">
          <el-date-picker
            v-model="formData.lastVerificationDate"
            type="date"
            value-format="x"
            placeholder="选择最近核对日期"
          />
        </el-form-item> -->
        
      </el-tab-pane>
      <el-tab-pane label="维保信息" name="second">
        <el-form-item label="维保厂商" prop="maintainerId">
          <el-input v-model="formData.maintainerId" placeholder="请输入维保厂商" />
        </el-form-item>
        <!-- <el-form-item label="联系人" prop="contacts">
          <el-input v-model="formData.contacts" placeholder="请输入联系人" />
        </el-form-item> -->
        <el-form-item label="维保开始时间" prop="maintenanceStartDate">
          <el-date-picker
            v-model="formData.maintenanceStartDate"
            type="date"
            value-format="x"
            placeholder="选择维保开始时间"
          />
        </el-form-item>
        <el-form-item label="维保到期时间" prop="maintenanceEndDate">
          <el-date-picker
            v-model="formData.maintenanceEndDate"
            type="date"
            value-format="x"
            placeholder="选择维保到期时间"
          />
        </el-form-item>
        <el-form-item label="维保状态" prop="maintenanceStatus">
          <!-- <el-radio-group v-model="formData.maintenanceStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group> -->
          <el-select filterable v-model="formData.maintenanceStatus" class="!w-240px" placeholder="管理人员" clearable>
            <el-option
            v-for="dict in getStrDictOptions(DICT_TYPE.eam_wb_status)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="联系方式" prop="contactInformation">
          <el-input v-model="formData.contactInformation" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="负责人" prop="director">
          <el-input v-model="formData.director" placeholder="请输入负责人" />
        </el-form-item>
        <el-form-item label="维保价格" prop="maintenancePrice">
          <el-input v-model="formData.maintenancePrice" placeholder="请输入维保价格" />
        </el-form-item> -->
        <el-form-item label="维保方式" prop="maintenanceMethod">
          <el-input v-model="formData.maintenanceMethod" placeholder="请输入维保方式" />
        </el-form-item>
        <!-- <el-form-item label="建议维保方式" prop="suggestMaintenanceMethod">
          <el-input v-model="formData.suggestMaintenanceMethod" placeholder="请输入建议维保方式" />
        </el-form-item>
        <el-form-item label="维保备注" prop="maintenanceNotes">
          <el-input v-model="formData.maintenanceNotes" placeholder="请输入维保备注" />
        </el-form-item> -->
      </el-tab-pane>
      <el-tab-pane label="财产信息" name="third">
        <!-- <el-form-item label="财务分类" prop="financialCategoryId">
          <el-input v-model="formData.financialCategoryId" placeholder="请输入财务分类" />
        </el-form-item> -->
        <el-form-item label="财务编号" prop="financialCode">
          <el-input v-model="formData.financialCode" placeholder="请输入财务编号" />
        </el-form-item>
        <!-- <el-form-item label="财务选项" prop="financialOption">
          <el-input v-model="formData.financialOption" placeholder="请输入财务选项" />
        </el-form-item> -->
        <!-- <el-form-item label="费用项目" prop="expenseItem">
          <el-select filterable v-model="formData.expenseItem" class="!w-240px" placeholder="管理人员" clearable>
            <el-option
            v-for="dict in getStrDictOptions(DICT_TYPE.eam_fy_item)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            />
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="资产供应商" prop="supplierId">
          <el-input v-model="formData.supplierId" placeholder="请输入资产供应商" />
        </el-form-item>
        <el-form-item label="客户信息" prop="customerInfo">
          <el-input v-model="formData.customerInfo" placeholder="请输入客户信息" />
        </el-form-item>
        <el-form-item label="含税总值,(含税数量>2)" prop="taxAmountPrice">
          <el-input v-model="formData.taxAmountPrice" placeholder="请输入含税总值,(含税数量>2)" />
        </el-form-item>
        <el-form-item label="未税总值,(数量>2)" prop="totalAmountPrice">
          <el-input v-model="formData.totalAmountPrice" placeholder="请输入未税总值,(数量>2)" />
        </el-form-item>
        <el-form-item label="含税单价,(含税)" prop="purchaseUnitPrice">
          <el-input v-model="formData.purchaseUnitPrice" placeholder="请输入含税单价,(含税)" />
        </el-form-item>
        <el-form-item label="资产原值,(未税)" prop="originalUnitPrice">
          <el-input v-model="formData.originalUnitPrice" placeholder="请输入资产原值,(未税)" />
        </el-form-item> -->
        <el-form-item label="资产净值" prop="navPrice">
          <el-input v-model="formData.navPrice" placeholder="请输入资产净值" />
        </el-form-item>
        <!-- <el-form-item label="已用期限,(月)" prop="assetUsedServiceLife">
          <el-input v-model="formData.assetUsedServiceLife" placeholder="请输入已用期限,(月)" />
        </el-form-item>
        <el-form-item label="最后折旧" prop="depreciationId">
          <el-input v-model="formData.depreciationId" placeholder="请输入最后折旧" />
        </el-form-item>
        <el-form-item label="最后折旧时间" prop="depreciationOperTime">
          <el-date-picker
            v-model="formData.depreciationOperTime"
            type="date"
            value-format="x"
            placeholder="选择最后折旧时间"
          />
        </el-form-item>
        <el-form-item label="残值率" prop="residualsRate">
          <el-input v-model="formData.residualsRate" placeholder="请输入残值率" />
        </el-form-item>
        <el-form-item label="残值" prop="residualsPrice">
          <el-input v-model="formData.residualsPrice" placeholder="请输入残值" />
        </el-form-item> -->
        <el-form-item label="税额" prop="taxAmountRate">
          <el-input v-model="formData.taxAmountRate" placeholder="请输入税额" />
        </el-form-item>
        <!-- <el-form-item label="本年折旧" prop="currentYearDepreciation">
          <el-input v-model="formData.currentYearDepreciation" placeholder="请输入本年折旧" />
        </el-form-item>
        <el-form-item label="折旧年份" prop="depreciationYear">
          <el-input v-model="formData.depreciationYear" placeholder="请输入折旧年份" />
        </el-form-item>
        <el-form-item label="累计折旧" prop="accumulatedDepreciation">
          <el-input v-model="formData.accumulatedDepreciation" placeholder="请输入累计折旧" />
        </el-form-item>
        <el-form-item label="月折金额" prop="monthDepreciationPrice">
          <el-input v-model="formData.monthDepreciationPrice" placeholder="请输入月折金额" />
        </el-form-item>
        <el-form-item label="登记时间" prop="entryTime">
          <el-date-picker
            v-model="formData.entryTime"
            type="date"
            value-format="x"
            placeholder="选择登记时间"
          />
        </el-form-item>-->
        <el-form-item label="财务备注" prop="financialNotes">
          <el-input v-model="formData.financialNotes" placeholder="请输入财务备注" />
        </el-form-item>
        <!-- <el-form-item label="设备编号" prop="equipmentCode">
          <el-input v-model="formData.equipmentCode" placeholder="请输入设备编号" />
        </el-form-item> -->
        <!-- <el-form-item label="启停状态" prop="equipmentStatus">
          <el-radio-group v-model="formData.equipmentStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <!-- <el-form-item label="设备IP" prop="equipmentIp">
          <el-input v-model="formData.equipmentIp" placeholder="请输入设备IP" />
        </el-form-item>
        <el-form-item label="管理IP" prop="manageIp">
          <el-input v-model="formData.manageIp" placeholder="请输入管理IP" />
        </el-form-item>
        <el-form-item label="设备CPU" prop="equipmentCpu">
          <el-input v-model="formData.equipmentCpu" placeholder="请输入设备CPU" />
        </el-form-item>
        <el-form-item label="设备内存" prop="equipmentMemory">
          <el-input v-model="formData.equipmentMemory" placeholder="请输入设备内存" />
        </el-form-item>
      
        <el-form-item label="设备配置" prop="equipmentConf">
          <el-input v-model="formData.equipmentConf" placeholder="请输入设备配置" />
        </el-form-item>
        <el-form-item label="设备运行环境" prop="equipmentEnvironmentCode">
          <el-input v-model="formData.equipmentEnvironmentCode" placeholder="请输入设备运行环境" />
        </el-form-item>
        <el-form-item label="设备序列号" prop="equipmentSerialNumber">
          <el-input v-model="formData.equipmentSerialNumber" placeholder="请输入设备序列号" />
        </el-form-item>
        <el-form-item label="设备机柜" prop="rackId">
          <el-input v-model="formData.rackId" placeholder="请输入设备机柜" />
        </el-form-item>
        <el-form-item label="短标签1" prop="label">
          <el-input v-model="formData.label" placeholder="请输入短标签1" />
        </el-form-item>
        <el-form-item label="短标签3" prop="label3">
          <el-input v-model="formData.label3" placeholder="请输入短标签3" />
        </el-form-item>
        <el-form-item label="短标签5" prop="label5">
          <el-input v-model="formData.label5" placeholder="请输入短标签5" />
        </el-form-item>
        <el-form-item label="长标签4" prop="label4">
          <el-input v-model="formData.label4" placeholder="请输入长标签4" />
        </el-form-item>
        <el-form-item label="长标签2" prop="label2">
          <el-input v-model="formData.label2" placeholder="请输入长标签2" />
        </el-form-item>
        <el-form-item label="单据" prop="billId">
          <el-input v-model="formData.billId" placeholder="请输入单据" />
        </el-form-item>
        <el-form-item label="巡检时间" prop="lastInspectTime">
          <el-date-picker
            v-model="formData.lastInspectTime"
            type="date"
            value-format="x"
            placeholder="选择巡检时间"
          />
        </el-form-item>
        <el-form-item label="经度数据" prop="longitude">
          <el-input v-model="formData.longitude" placeholder="请输入经度数据" />
        </el-form-item>
        <el-form-item label="维度数据" prop="dimension">
          <el-input v-model="formData.dimension" placeholder="请输入维度数据" />
        </el-form-item> -->
      </el-tab-pane>
    </el-tabs>


     
    
      
     
    
      
      
  
    </el-form>
    <template #footer>
      <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>
<script setup lang="ts">
import * as AssetApi from '@/api/eam/asset'
import * as CatalogApi from '@/api/eam/catalog'
import * as DeptApi from '@/api/system/dept'
import * as UserApi from '@/api/system/user'
import * as ManufacturerFormApi from '@/api/eam/manufacturer'
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'

const { t } = useI18n() // 国际化
const activeName = ref('basic')
const message = useMessage() // 消息弹窗
import { useUserStore } from '@/store/modules/user'
import { defaultProps, handleTree } from '@/utils/tree'
import dayjs from 'dayjs'
const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formType = ref('') // 表单的类型：create - 新增；update - 修改
const formData: any = ref({
  id: undefined,
  categoryId: undefined,
  categoryCode: undefined,
  businessCode: undefined,
  procId: undefined,
  status: undefined,
  batchCode: undefined,
  ownerCode: undefined,
  assetCode: undefined,
  assetStatus: undefined,
  display: undefined,
  cleanOutType: undefined,
  cleanOut: undefined,
  cleanTime: undefined,
  goodsId: undefined,
  name: undefined,
  manufacturerId: undefined,
  model: undefined,
  pictureId: undefined,
  unit: undefined,
  serviceLife: undefined,
  safetyLevelCode: undefined,
  serialNumber: undefined,
  ownCompanyId: undefined,
  managerId: undefined,
  useOrganizationId: undefined,
  useUserId: undefined,
  regionId: undefined,
  positionId: undefined,
  positionDetail: undefined,
  warehouseId: undefined,
  goodsStockId: undefined,
  sourceId: undefined,
  assetNumber: undefined,
  remainNumber: undefined,
  purchaseDate: undefined,
  productionDate: undefined,
  registerDate: undefined,
  rfid: undefined,
  attach: undefined,
  lastVerificationDate: undefined,
  purpose: undefined,
  assetNotes: undefined,
  maintainerId: undefined,
  maintainerName: undefined,
  maintenanceStatus: undefined,
  maintenancePrice: undefined,
  maintenanceMethod: undefined,
  suggestMaintenanceMethod: undefined,
  contacts: undefined,
  contactInformation: undefined,
  director: undefined,
  maintenanceStartDate: undefined,
  maintenanceEndDate: undefined,
  maintenanceNotes: undefined,
  financialCategoryId: undefined,
  financialCode: undefined,
  financialOption: undefined,
  expenseItem: undefined,
  supplierId: undefined,
  customerInfo: undefined,
  taxAmountPrice: undefined,
  totalAmountPrice: undefined,
  purchaseUnitPrice: undefined,
  originalUnitPrice: undefined,
  navPrice: undefined,
  assetUsedServiceLife: undefined,
  depreciationId: undefined,
  depreciationOperTime: undefined,
  residualsRate: undefined,
  residualsPrice: undefined,
  taxAmountRate: undefined,
  currentYearDepreciation: undefined,
  depreciationYear: undefined,
  accumulatedDepreciation: undefined,
  monthDepreciationPrice: undefined,
  entryTime: undefined,
  financialNotes: undefined,
  equipmentCode: undefined,
  equipmentStatus: undefined,
  equipmentIp: undefined,
  manageIp: undefined,
  equipmentCpu: undefined,
  equipmentMemory: undefined,
  equipmentLabel: undefined,
  equipmentConf: undefined,
  equipmentEnvironmentCode: undefined,
  equipmentSerialNumber: undefined,
  rackId: undefined,
  rackUpNumber: undefined,
  rackDownNumber: undefined,
  label: undefined,
  label3: undefined,
  label5: undefined,
  label4: undefined,
  label2: undefined,
  billId: undefined,
  lastInspectTime: undefined,
  longitude: undefined,
  dimension: undefined,
  internalControlLabel: undefined,
  collectionId: undefined,
  borrowId: undefined,
  scrapId: undefined,
  handleId: undefined,
  originatorId: undefined,
  chsType: undefined,
  chsStatus: undefined,
  chsVersion: undefined,
  changeInstanceId: undefined,
  summary: undefined,
  latestApproverId: undefined,
  latestApproverName: undefined,
  nextApproverIds: undefined,
  nextApproverNames: undefined,
  approvalOpinion: undefined,
  assetSelectedData: undefined,
  deptId: useUserStore().getUser.deptId,
  userId: undefined,
})

/** 根据选择的部门筛选员工清单 */
// const userListByDeptId = computed(() =>
//   formData.deptId
//     ? userList.value.filter((u: any) => u.deptId === formData.deptId)
//     : []
// )

const deptList = ref<Tree[]>([]) // 部门树形结构
const userList = ref<UserApi.UserVO[]>([]) // 全量用户清单
const CatalogList: any = ref([]) 
// const ManufacturerList: any = ref([]) 

const formRules = reactive({
  categoryId: [
      { required: true, message: '请选择资产分类', trigger: 'change' }
    ],
     ownCompanyId: [
      { required: true, message: '请选择归属公司', trigger: 'change' }
    ],
    ownerCode: [
      { required: true, message: '请选择归属', trigger: 'change' }
    ],
    name: [
      { required: true, message: '资产名称'}
    ],
    useOrganizationId: [
      { required: true, message: '归属部门',  trigger: 'change' }
    ],
    assetStatus: [
      { required: true, message: '资产状态',  trigger: 'change' }
    ],
})
const formRef = ref() // 表单 Ref
/** 初始化 */
onMounted(async () => {
  console.log('AssetForm.vue')
  deptList.value = handleTree(await DeptApi.getDeptPage({}))
  userList.value = handleTree(await UserApi.getSimpleUserList())
   let res: any = await CatalogApi.getCatalogPage({
    pageNo: 1,
    pageSize: 10000
  })
  res = res.list
  CatalogList.value = handleTree(res)

  //  let res2: any = await ManufacturerFormApi.getManufacturerPage({
  //   pageNo: 1,
  //   pageSize: 100
  // })
  // res2 = res2.list
  // ManufacturerList.value = res2
})

/** 打开弹窗 */
const open = async (type: string, id?: number) => {
  dialogVisible.value = true
  dialogTitle.value = t('action.' + type)
  formType.value = type
  resetForm()
  // 修改时，设置数据
  if (id) {
    formLoading.value = true
    try {
      let res: any = await AssetApi.getAsset(id)
      res.categoryId = Number(res.categoryId)
      res.ownCompanyId = Number(res.ownCompanyId)
      res.managerId = Number(res.managerId)
      res.useUserId = Number(res.useUserId)
      res.maintenanceStartDate = res.maintenanceStartDate ? dayjs(res.maintenanceStartDate).format('YYYY-MM-DD') : '';
      res.maintenanceEndDate = res.maintenanceEndDate ? dayjs(res.maintenanceEndDate).format('YYYY-MM-DD') : '';
      res.useOrganizationId = Number(res.useOrganizationId)
      console.log(res, 'res')
      formData.value = res
    } finally {
      formLoading.value = false
    }
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const submitForm = async () => {
  // 校验表单
  await formRef.value.validate()
  // 提交请求
  formLoading.value = true
  try {
    const data = formData.value as unknown as AssetApi.AssetVO
    data.maintenanceEndDate = data.maintenanceEndDate ? dayjs(data.maintenanceEndDate).format('YYYY-MM-DD') : "";
    data.maintenanceStartDate =  data.maintenanceStartDate ? dayjs(data.maintenanceStartDate).format('YYYY-MM-DD') : '';
    if (formType.value === 'create') {
      await AssetApi.createAsset(data)
      message.success(t('common.createSuccess'))
    } else {
      await AssetApi.updateAsset(data)
      message.success(t('common.updateSuccess'))
    }
    dialogVisible.value = false
    // 发送操作成功的事件
    emit('success')
  } finally {
    formLoading.value = false
  }
}

/** 重置表单 */
const resetForm = () => {
  formData.value = {
    id: undefined,
    categoryId: undefined,
    categoryCode: undefined,
    businessCode: undefined,
    procId: undefined,
    status: undefined,
    batchCode: undefined,
    ownerCode: undefined,
    assetCode: undefined,
    assetStatus: undefined,
    display: undefined,
    cleanOutType: undefined,
    cleanOut: undefined,
    cleanTime: undefined,
    goodsId: undefined,
    name: undefined,
    manufacturerId: undefined,
    model: undefined,
    pictureId: undefined,
    unit: undefined,
    serviceLife: undefined,
    safetyLevelCode: undefined,
    serialNumber: undefined,
    ownCompanyId: undefined,
    managerId: undefined,
    useOrganizationId: undefined,
    useUserId: undefined,
    regionId: undefined,
    positionId: undefined,
    positionDetail: undefined,
    warehouseId: undefined,
    goodsStockId: undefined,
    sourceId: undefined,
    assetNumber: undefined,
    remainNumber: undefined,
    purchaseDate: undefined,
    productionDate: undefined,
    registerDate: undefined,
    rfid: undefined,
    attach: undefined,
    lastVerificationDate: undefined,
    purpose: undefined,
    assetNotes: undefined,
    maintainerId: undefined,
    maintainerName: undefined,
    maintenanceStatus: undefined,
    maintenancePrice: undefined,
    maintenanceMethod: undefined,
    suggestMaintenanceMethod: undefined,
    contacts: undefined,
    contactInformation: undefined,
    director: undefined,
    maintenanceStartDate: undefined,
    maintenanceEndDate: undefined,
    maintenanceNotes: undefined,
    financialCategoryId: undefined,
    financialCode: undefined,
    financialOption: undefined,
    expenseItem: undefined,
    supplierId: undefined,
    customerInfo: undefined,
    taxAmountPrice: undefined,
    totalAmountPrice: undefined,
    purchaseUnitPrice: undefined,
    originalUnitPrice: undefined,
    navPrice: undefined,
    assetUsedServiceLife: undefined,
    depreciationId: undefined,
    depreciationOperTime: undefined,
    residualsRate: undefined,
    residualsPrice: undefined,
    taxAmountRate: undefined,
    currentYearDepreciation: undefined,
    depreciationYear: undefined,
    accumulatedDepreciation: undefined,
    monthDepreciationPrice: undefined,
    entryTime: undefined,
    financialNotes: undefined,
    equipmentCode: undefined,
    equipmentStatus: undefined,
    equipmentIp: undefined,
    manageIp: undefined,
    equipmentCpu: undefined,
    equipmentMemory: undefined,
    equipmentLabel: undefined,
    equipmentConf: undefined,
    equipmentEnvironmentCode: undefined,
    equipmentSerialNumber: undefined,
    rackId: undefined,
    rackUpNumber: undefined,
    rackDownNumber: undefined,
    label: undefined,
    label3: undefined,
    label5: undefined,
    label4: undefined,
    label2: undefined,
    billId: undefined,
    lastInspectTime: undefined,
    longitude: undefined,
    dimension: undefined,
    internalControlLabel: undefined,
    collectionId: undefined,
    borrowId: undefined,
    scrapId: undefined,
    handleId: undefined,
    originatorId: undefined,
    chsType: undefined,
    chsStatus: undefined,
    chsVersion: undefined,
    changeInstanceId: undefined,
    summary: undefined,
    latestApproverId: undefined,
    latestApproverName: undefined,
    nextApproverIds: undefined,
    nextApproverNames: undefined,
    approvalOpinion: undefined,
    assetSelectedData: undefined,
  }
  formRef.value?.resetFields()
}
</script>